import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { map } from 'rxjs/operators';

import { AreaConfig } from '../../services/area-config';
import { LastUrlService } from '../../services/last-url.service';

@Component({
    selector: 'm-area-config-list',
    templateUrl: './area-config-list.component.html',
    styleUrls: ['./area-config-list.component.scss']
})
export class AreaConfigListComponent implements OnInit {
    constructor(private route: ActivatedRoute,
        private router: Router,
        private urlService: LastUrlService) { }

    result$ = this.route.data.pipe(map(data => data['list']));

    ngOnInit() {
        this.route.url.subscribe(urls => this.urlService.setURL(urls.join(',')));
    }

    preview(item: AreaConfig) {
        this.router.navigate([item.id], { relativeTo: this.route });
    }
}
